# $Id$
# Maintainer: Angel Velasquez <angvp@archlinux.org> 
# Maintainer: AndyRTR <andyrtr@archlinux.org>

pkgbase=hunspell-es
pkgname=(hunspell-es hyphen-es mythes-es)
pkgver=2.2
pkgrel=1
epoch=1
pkgdesc="Spanish hunspell dictionaries"
arch=(any)
url="https://github.com/sbosio/rla-es"
license=('LGPL3')
noextract=(es_ANY.oxt es_AR.oxt es_BO.oxt es_CL.oxt es_CO.oxt 
           es_CR.oxt es_CU.oxt es_DO.oxt es_EC.oxt es_ES.oxt 
           es_GT.oxt es_HN.oxt es_MX.oxt es_NI.oxt es_PA.oxt 
           es_PE.oxt es_PR.oxt es_PY.oxt es_SV.oxt es_UY.oxt es_VE.oxt)
source=("https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_ANY.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_AR.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_BO.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_CL.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_CO.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_CR.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_CU.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_DO.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_EC.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_ES.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_GT.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_HN.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_MX.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_NI.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_PA.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_PE.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_PR.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_PY.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_SV.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_UY.oxt"
        "https://github.com/sbosio/rla-es/releases/download/v$pkgver/es_VE.oxt")
md5sums=('5d2a621da5e00871f5d43537b343a7c5'
         '9c2e0eb4124a4f8bcc1f90fbcc22a729'
         '2ff909220bf829bb08651ad1243f766f'
         '631ff1bd78a377077a84e91895db8554'
         'b8030f0e018b9a0b879916c2bc6b99cc'
         'bfb8b65dc58cfadb456247b3739a830b'
         '607df889fcd7f7f70cd31e5143a0ab22'
         '97ffa11e769f53f76f939dc1c5c45c6b'
         '7639d8d83c64d45b34f88b2cb30771ad'
         '8f6d52b55a41c1108234f625232131e4'
         '21291ce4ca017306321879706d6b8f52'
         'e7076ac541f547a314359d1795255ee6'
         '69919517517437a75603173d0fa9cb2c'
         'cd573e82a11eacccd1cb12cfa6e89797'
         'cd1a3ce9cf60621261b50c1cd975ba42'
         '5a8216aabea79171b7e2edaeb0077d6f'
         '7953ae81200fb978a0d44d11fcc6b7fd'
         '35795c6e097d2cff48774da834416988'
         '5a2b8f9a15542724a3ae12d7206af256'
         'baea8f23e87f509023461df40d1239b2'
         '9c71676888b8fab9f4dd7b8a88a44c68')

package_hunspell-es() {
  optdepends=('hunspell:  the spell checking libraries and apps')

  for file in *.oxt; do
    LANG=en_US.utf8 bsdtar -xf $file
  done

  install -dm755 "${pkgdir}/usr/share/hunspell"
  install -m644 es_*.dic es_*.aff "$pkgdir/usr/share/hunspell"

  # the symlinks
  install -dm755 "${pkgdir}/usr/share/myspell/dicts"
  pushd "$pkgdir/usr/share/myspell/dicts"
    for file in "$pkgdir"/usr/share/hunspell/*; do
      ln -sv /usr/share/hunspell/$(basename $file) .
    done
  popd
  
  # docs
  install -dm755 "${pkgdir}/usr/share/doc/$pkgname"
  install -m644 README.txt "$pkgdir/usr/share/doc/$pkgname"
}

package_hyphen-es() {
  pkgdesc="Spanish hyphenation rules"
  optdepends=('hyphen: offers hyphenation library functions')

  install -Dm644 hyph_es_ANY.dic "$pkgdir/usr/share/hyphen/hyph_es_ANY.dic"

  pushd "$pkgdir/usr/share/hyphen/"
  es_ES_aliases="es_AR es_BO es_CL es_CO es_CR es_CU es_DO es_EC es_ES es_GT es_HN es_MX es_NI es_PA es_PE es_PR es_SV es_UY es_VE"
  for lang in $es_ES_aliases; do
        ln -s hyph_es_ANY.dic hyph_$lang.dic
  done
  popd

  # the symlinks
  install -dm755 "${pkgdir}/usr/share/myspell/dicts"
  pushd "$pkgdir/usr/share/myspell/dicts"
    for file in "$pkgdir"/usr/share/hyphen/*; do
      ln -sv /usr/share/hyphen/$(basename $file) .
    done
  popd
  
  # docs
  install -Dm644 README_hyph_es_ANY.txt "${pkgdir}/usr/share/doc/$pkgname/README_hyph_es_ANY.txt"
}

package_mythes-es() {
  pkgdesc="Spanish thesaurus"
  optdepends=('libmythes: offers thesaurus library functions')

  LANG=en_US.utf8 bsdtar -xf es_ANY.oxt
  install -dm755 "${pkgdir}/usr/share/mythes"
  install -m644 th_es_ES_v2.* "$pkgdir/usr/share/mythes"

  pushd "$pkgdir/usr/share/mythes/"
  es_ES_aliases="es_AR es_BO es_CL es_CO es_CR es_CU es_DO es_EC es_GT es_HN es_MX es_NI es_PA es_PE es_PR es_SV es_UY es_VE"
  for lang in $es_ES_aliases; do
        ln -s th_es_ES_v2.idx "th_"$lang"_v2.idx"
        ln -s th_es_ES_v2.dat "th_"$lang"_v2.dat"
  done
  popd

  # the symlinks
  install -dm755 "${pkgdir}/usr/share/myspell/dicts"
  pushd "$pkgdir/usr/share/myspell/dicts"
  for file in "$pkgdir"/usr/share/mythes/*; do
    ln -sv /usr/share/mythes/$(basename $file) .
  done
  popd
  
  # docs
  install -Dm644 README_th_es_ES.txt "${pkgdir}/usr/share/doc/$pkgname/README_th_es_ES.txt"
}
